/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LoginWindow.java
 *
 * Created on Jul 30, 2011, 11:49:44 PM
 */

package INTROSE_MP;

import javax.swing.JFrame;

        
/**
 *
 * @author Paolo
 */
public class LoginWindow extends javax.swing.JFrame {
    
    /** Creates new form LoginWindow */
    public LoginWindow() {
        initComponents();
        loginError.setVisible(false);
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        usernameLabel = new javax.swing.JLabel();
        pwdLabel = new javax.swing.JLabel();
        usernameTxt = new javax.swing.JTextField();
        cancelLogin = new javax.swing.JButton();
        loginButton = new javax.swing.JButton();
        pwdTxt = new javax.swing.JPasswordField();
        loginError = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Login - Pusong Pinoy");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        usernameLabel.setText("Username:");
        getContentPane().add(usernameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 16, -1, -1));

        pwdLabel.setText("Password:");
        getContentPane().add(pwdLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 45, -1, -1));
        getContentPane().add(usernameTxt, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 13, 237, -1));

        cancelLogin.setText("Cancel");
        cancelLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelLogin(evt);
            }
        });
        getContentPane().add(cancelLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(246, 71, -1, -1));

        loginButton.setText("Login");
        loginButton.setOpaque(false);
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginAction(evt);
            }
        });
        getContentPane().add(loginButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(176, 71, -1, -1));
        getContentPane().add(pwdTxt, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 42, 237, -1));

        loginError.setForeground(new java.awt.Color(255, 0, 0));
        loginError.setText("*Invalid login.");
        loginError.setToolTipText("Please ensure that your login details are correct.");
        getContentPane().add(loginError, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 75, -1, -1));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/BG.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(-400, -30, 740, 140));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelLogin(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelLogin
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_cancelLogin

    private void loginAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginAction
        // TODO add your handling code here:
        
        char[] aPwd = pwdTxt.getPassword();
        String sPwd = aPwd.toString();
        ManagerWindow MgrWin = new ManagerWindow();
        
        if("".equals(usernameTxt.getText()) || "".equals(sPwd))
            loginError.setVisible(true);
        
        else {
            MgrWin.setVisible(true);
            MgrWin.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            MgrWin.setLocationRelativeTo(null);
        }
        this.dispose();
    }//GEN-LAST:event_loginAction

    /**
    * @param args the command line arguments
    */
    /**public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LoginWindow().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelLogin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton loginButton;
    private javax.swing.JLabel loginError;
    private javax.swing.JLabel pwdLabel;
    private javax.swing.JPasswordField pwdTxt;
    private javax.swing.JLabel usernameLabel;
    private javax.swing.JTextField usernameTxt;
    // End of variables declaration//GEN-END:variables

}
